﻿using UnityEngine;
using System.Collections;
using System;
using FSM;

public class FSMController
{
    private FSMMachineBase m_machine;
    public FSMMachineBase Machine
    {
        get
        {
            return m_machine;
        }
    }

    private BaseGameEntity m_unit;

    public void UpdatePerceptions(int t)
    {
        m_machine.UpdateMachine(t);
    }

    public void InitMachine(string name)
    {
        string className = "FSMMachine" + name;
        Type classType = Type.GetType(className);
        m_machine = Activator.CreateInstance(classType, this) as FSMMachineBase;
    }

    public int GetState()
    {
        if (m_machine != null && m_machine.CurrentState != null)
        {
            return m_machine.CurrentState.type;
        }
        return 0;
    }

    public FSMController Init(BaseGameEntity unit, string name)
    {
        m_unit = unit;
        InitMachine(name);
        return this;
    }

    public void Update()
    {
        UpdatePerceptions(1);
    }
}
